#ifndef SINGLEGAME_H
#define SINGLEGAME_H

#include "Board.h"
#include "Step.h"
#include <QtCore/QFile>
#include <QtCore/QTextStream>
#include <ctime>

class SingleGame : public Board
{
    Q_OBJECT
public:

    SingleGame()
    {
        _level=4;
        initGame();
        isCanJu=false;
    }
    virtual void click(int id,int row,int col);

    //得到最好的一步
    Step* getBestMove();
    //获取所有可能走的步骤
    void getAllPossibleMove(QVector<Step*>& steps);

    //尝试走步
    void fakeMove(Step* step);
    //撤销尝试走步
    void unfakeMove(Step* step);
    //计算当前局面分数
    int calcScore();

    //获取最小分值
    int getMinScore(int level,int maxScore);
    //获取最大分值
    int getMaxScore(int level,int minScore);
    //考虑的深度
    int _level;

    //重写开始游戏
    virtual void StartClick();
    //重写悔棋
    virtual void RegretClick();

    //重写是否悔棋
    virtual void isShowButton(bool isShow);

    //初始化开局库
    QStringList openList;
    void initGame();
    //保存开局记录
    QString history;


    //增加残局
    //是否是残局
    bool isCanJu;
    //名称
    QString puName;
    //初始位置
    QString location;
    //最优走法
    QString moveList;
    //获胜目标
    QString result;
    void startCanJu();
    //end
    //获取位置棋子分数
    int getPieceScore(int id);

    //车价值
    int C[10][10]={
        {206, 208, 207, 213, 214, 213, 207, 208, 206},
        {206, 212, 209, 216, 233, 216, 209, 212, 206},
        {206, 208, 207, 214, 216, 214, 207, 208, 206},
        {206, 213, 213, 216, 216, 216, 213, 213, 206},
        {208, 211, 211, 214, 215, 214, 211, 211, 208},
        {208, 212, 212, 214, 215, 214, 212, 212, 208},
        {204, 209, 204, 212, 214, 212, 204, 209, 204},
        {198, 208, 204, 212, 212, 212, 204, 208, 198},
        {200, 208, 206, 212, 200, 212, 206, 208, 200},
        {194, 206, 204, 212, 200, 212, 204, 206, 194}
    };

    //马价值
    int M[10][10]={
        {90, 90, 90, 96, 90, 96, 90, 90, 90},
        {90, 96,103, 97, 94, 97,103, 96, 90},
        {92, 98, 99,103, 99,103, 99, 98, 92},
        {93,108,100,107,100,107,100,108, 93},
        {90,100, 99,103,104,103, 99,100, 90},

        {90, 98,101,102,103,102,101, 98, 90},
        {92, 94, 98, 95, 98, 95, 98, 94, 92},
        {93, 92, 94, 95, 92, 95, 94, 92, 93},
        {85, 90, 92, 93, 78, 93, 92, 90, 85},
        {88, 85, 90, 88, 90, 88, 90, 85, 88}
    };

    //相价值
    int X[10][10]={
        {0, 0,20, 0, 0, 0,20, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0,23, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0,20, 0, 0, 0,20, 0, 0},

        {0, 0,20, 0, 0, 0,20, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0},
        {18,0, 0, 0,23, 0, 0, 0,18},
        {0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0,20, 0, 0, 0,20, 0, 0}
    };

    //士价值
    int S[10][10]={
        {0, 0, 0,20, 0,20, 0, 0, 0},
        {0, 0, 0, 0,23, 0, 0, 0, 0},
        {0, 0, 0,20, 0,20, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0},

        {0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0,20, 0,20, 0, 0, 0},
        {0, 0, 0, 0,23, 0, 0, 0, 0},
        {0, 0, 0,20, 0,20, 0, 0, 0}
    };

    //奖价值
    int J[10][10]={
        {0, 0, 0, 8888, 8888, 8888, 0, 0, 0},
        {0, 0, 0, 8888, 8888, 8888, 0, 0, 0},
        {0, 0, 0, 8888, 8888, 8888, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0},

        {0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 8888, 8888, 8888, 0, 0, 0},
        {0, 0, 0, 8888, 8888, 8888, 0, 0, 0},
        {0, 0, 0, 8888, 8888, 8888, 0, 0, 0}
    };

    //炮价值
    int P[10][10]={

        {100, 100,  96, 91,  90, 91,  96, 100, 100},
        { 98,  98,  96, 92,  89, 92,  96,  98,  98},
        { 97,  97,  96, 91,  92, 91,  96,  97,  97},
        { 96,  99,  99, 98, 100, 98,  99,  99,  96},
        { 96,  96,  96, 96, 100, 96,  96,  96,  96},

        { 95,  96,  99, 96, 100, 96,  99,  96,  95},
        { 96,  96,  96, 96,  96, 96,  96,  96,  96},
        { 97,  96, 100, 99, 101, 99, 100,  96,  97},
        { 96,  97,  98, 98,  98, 98,  98,  97,  96},
        { 96,  96,  97, 99,  99, 99,  97,  96,  96}
    };

    //卒价值
    int Z[10][10]={
        { 9,  9,  9, 11, 13, 11,  9,  9,  9},
        {19, 24, 34, 42, 44, 42, 34, 24, 19},
        {19, 24, 32, 37, 37, 37, 32, 24, 19},
        {19, 23, 27, 29, 30, 29, 27, 23, 19},
        {14, 18, 20, 27, 29, 27, 20, 18, 14},

        { 7,  0, 13,  0, 16,  0, 13,  0,  7},
        { 7,  0,  7,  0, 15,  0,  7,  0,  7},
        { 0,  0,  0,  0,  0,  0,  0,  0,  0},
        { 0,  0,  0,  0,  0,  0,  0,  0,  0},
        { 0,  0,  0,  0,  0,  0,  0,  0,  0}
    };


public slots:
    void computerMove();
    //重写再来一局
    virtual void AgainClick();

};

#endif // SINGLEGAME_H
